{% extends "base.html" %}

{% block title %}在线学习 - {{ super() }}{% endblock %}

{% block content %}
<div class="container">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>在线学习</h1>
        {% if current_user.is_authenticated and current_user.role == 'admin' %}
        <a href="{{ url_for('learning.create') }}" class="btn btn-primary">
            <i class="fas fa-plus"></i> 创建课程
        </a>
        {% endif %}
    </div>

    <div class="row">
        {% for course in courses.items %}
        <div class="col-md-6 mb-4">
            <div class="card h-100">
                <div class="card-body">
                    <h5 class="card-title">
                        <a href="{{ url_for('learning.detail', id=course.id) }}" class="text-decoration-none">
                            {{ course.title }}
                        </a>
                    </h5>
                    <p class="card-text">{{ course.description[:200] }}...</p>
                    <div class="d-flex justify-content-between align-items-center">
                        <small class="text-muted">
                            <i class="fas fa-user"></i> {{ course.user.username }}
                            <span class="ms-2"><i class="fas fa-eye"></i> {{ course.views }}</span>
                        </small>
                        <small class="text-muted">
                            <i class="fas fa-clock"></i> {{ course.created_at.strftime('%Y-%m-%d') }}
                        </small>
                    </div>
                </div>
            </div>
        </div>
        {% else %}
        <div class="col-12">
            <div class="alert alert-info text-center">
                暂无课程内容
            </div>
        </div>
        {% endfor %}
    </div>

    {% if courses.pages > 1 %}
    <nav aria-label="Page navigation" class="mt-4">
        <ul class="pagination justify-content-center">
            {% for page_num in courses.iter_pages() %}
                {% if page_num %}
                    <li class="page-item {% if page_num == courses.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('learning.index', page=page_num) }}">{{ page_num }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
            {% endfor %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %} 